package com.zzc.emotisenseclassroom.controller.user;

import com.zzc.common.response.ZzcResponse;
import com.zzc.emotisenseclassroom.common.ResponseCodeEnum;
import com.zzc.emotisenseclassroom.domain.user.service.StudentService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * Copyright Zzc
 * FileName: StudentContoller
 * Author:   Zzc
 * Date:     2024/4/281:11
 * Description:学生信息控制器
 * hISTORY:
 * <author>  <time>     <version>    <desc>
 * 作者姓名   修改时间       版本号       描述
 * Zzc                   1.0.0
 */
@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService studentService;

    @PostMapping("/getStudnetInfo/bySchoolAndClass")
    public ZzcResponse getStudentListBySchoolAndClass(@RequestBody Map<String, Object> param){
        return ZzcResponse.success(ResponseCodeEnum.SEARCH_SUCCESS, studentService.getStudentListBySchoolAndClass(param));
    }

    @PostMapping("/getStudnetInfo/byCondition")
    public ZzcResponse getStudentListByCondition(@RequestBody Map<String, Object> param){
        return ZzcResponse.success(ResponseCodeEnum.SEARCH_SUCCESS, studentService.getStudentListByCondition(param));
    }

    @PostMapping("/count")
    public ZzcResponse countStudent(@RequestBody Map<String, String> requestData){
        String classIdStr = requestData.get("classId");
        Long classId = StringUtils.isNotBlank(classIdStr) ? Long.parseLong(classIdStr) : null;
        String schoolIdStr = requestData.get("schoolId");
        Long schoolId = StringUtils.isNotBlank(schoolIdStr) ? Long.parseLong(schoolIdStr) : null ;
        return ZzcResponse.success(ResponseCodeEnum.GET_LIST_SIZE_SUCCESS, studentService.countStudent(schoolId, classId));
    }

    @PostMapping("/conditionCount")
    public ZzcResponse conditionCountStudent(@RequestBody Map<String, String> requestData){
        return ZzcResponse.success(ResponseCodeEnum.GET_LIST_SIZE_SUCCESS, studentService.conditionCountStudent(requestData));
    }
}
